package com.hyt.it.ogt.ykcj.domain.vo;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hyt.it.ogt.ykcj.common.annotation.Excel;
import com.hyt.it.ogt.ykcj.common.constant.Constants;
import com.hyt.it.ogt.ykcj.common.enums.BizErrorCode;
import com.hyt.it.ogt.ykcj.common.exception.CustomException;

import cn.hutool.core.util.IdcardUtil;
import io.swagger.annotations.ApiModelProperty;

public class ServantExamineeInfoVo {

    /** ID */
    @ApiModelProperty(value = "ID")
    private String id;

    /** 考试ID */
    @ApiModelProperty(value = "考试ID")
    @Excel(name = "考试ID")
    private String examId;

    /** 考生名字 */
    @ApiModelProperty(value = "考生名字")
    @Excel(name = "考生名字")
    private String name;

    /** 准考证号 */
    @ApiModelProperty(value = "准考证号")
    @Excel(name = "准考证号")
    private String admissionNo;

    /** 身份证号 */
    @ApiModelProperty(value = "身份证号")
    @Excel(name = "身份证号")
    private String idcard;

    /** 性别 */
    @ApiModelProperty(value = "性别")
    @Excel(name = "性别")
    private String sex;

    /** 职位代码 */
    @ApiModelProperty(value = "职位代码")
    @Excel(name = "职位代码")
    private String bkzwdm;

    /** 单位代码（部门代码） */
    @ApiModelProperty(value = "单位代码（部门代码）")
    @Excel(name = "单位代码（部门代码）")
    private String bkdwdm;

    /** 是否已归档,默认否。Y-已归档，N-未归档 */
    @ApiModelProperty(value = "是否已归档,默认否。Y-已归档，N-未归档")
    @Excel(name = "是否已归档,默认否。Y-已归档，N-未归档")
    private String archivedStatus;

    /** 归档时间 */
    @ApiModelProperty(value = "归档时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "归档时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date archivedDate;

    /** 公务员考生信息成绩对象 */
    @ApiModelProperty(value = "公务员考生信息成绩对象")
    @Excel(name = "公务员考生信息成绩对象")
    private List<ServantExamineeSubjectGradeVo> gradeList;


    /** 科目ID */
    @ApiModelProperty(value = "科目ID")
    @Excel(name = "科目ID")
    private String subjectId;

    /** 科目名称 */
    @ApiModelProperty(value = "科目名称")
    @Excel(name = "科目名称")
    private String subjectName;

    /** 删除状态 */
    @ApiModelProperty(value = "删除状态(D:删除;N:未删除)")
    @Excel(name = "删除状态(D:删除;N:未删除)")
    private String delFlag;

    public void setId(String id)
    {
        this.id = id;
    }
    public String getId()
    {
        return id;
    }

    public void setExamId(String examId)
    {
        this.examId = examId;
    }
    public String getExamId()
    {
        return examId;
    }

    public void setName(String name)
    {
        this.name = name;
    }
    public String getName()
    {
        return name;
    }

    public void setAdmissionNo(String admissionNo)
    {
        this.admissionNo = admissionNo;
    }
    public String getAdmissionNo()
    {
        return admissionNo;
    }

    public void setIdcard(String idcard) {
        if (!IdcardUtil.isValidCard(idcard)) {
            throw new CustomException(BizErrorCode.GRADE_E0011);
        }
        this.idcard = idcard;
    }
    public String getIdcard()
    {
        return idcard;
    }

    public void setSex(String sex) {
        if (StringUtils.isEmpty(sex)) {
            // 通过身份证号获取性别
            if (Integer.parseInt(idcard.substring(16, 17)) % 2 == 0) {
                sex = Constants.SEX_WOMAN;
            } else {
                sex = Constants.SEX_MAN;
            }
        }
        this.sex = sex;
    }
    public String getSex() { return sex; }

    public void setBkzwdm(String bkzwdm) { this.bkzwdm = bkzwdm; }
    public String getBkzwdm() { return bkzwdm; }

    public String getBkdwdm() { return bkdwdm; }
    public void setBkdwdm(String bkdwdm) { this.bkdwdm = bkdwdm; }

    public void setArchivedStatus(String archivedStatus) { this.archivedStatus = archivedStatus; }
    public String getArchivedStatus() { return archivedStatus; }

    public void setArchivedDate(Date archivedDate) { this.archivedDate = archivedDate; }
    public Date getArchivedDate() { return archivedDate; }

    public List<ServantExamineeSubjectGradeVo> getGradeList() { return gradeList; }
    public void setGradeList(List<ServantExamineeSubjectGradeVo> gradeList) { this.gradeList = gradeList; }

    public String getSubjectId() { return subjectId; }
    public void setSubjectId(String subjectId) { this.subjectId = subjectId; }

    public String getSubjectName() { return subjectName; }
    public void setSubjectName(String subjectName) { this.subjectName = subjectName; }

    public String getDelFlag() { return delFlag == null ? "N":delFlag; }
    public void setDelFlag(String delFlag) { this.delFlag = delFlag; }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("examId", getExamId())
                .append("name", getName())
                .append("admissionNo", getAdmissionNo())
                .append("idcard", getIdcard())
                .append("sex", getSex())
                .append("bkzwdm", getBkzwdm())
                .append("bkdwdm", getBkdwdm())
                .append("archivedStatus", getArchivedStatus())
                .append("archivedDate", getArchivedDate())
                .append("gradeList", getGradeList())
                .toString();
    }

    public Map toMap() {
        Map<String, String> map = new HashMap<>();
        map.put("admissionNo", getAdmissionNo());
        map.put("name", getName());
        map.put("sex", getSex());
        map.put("idcard", getIdcard());
        map.put("bkzwdm", getBkzwdm());
        map.put("bkdwdm", getBkdwdm());
        return map;
    }
}
